import { DataEnum } from "../../datavo/DataEnum";
import Singleton from "../context/Singleton";

export default class Data extends Singleton {

    private static data: any;
    private static isReady: boolean;

    /**
     * @inner
     * @param progress 进度
     * @param refresh 强制刷新
     * @returns 
     */
    static loadData(progress: Laya.Handler, refresh: boolean = false) {

        if (this.data != null && !refresh) {
            progress.runWith(1);
            return;
        }

        this.data = Object.create(null);
        let sheets = DataEnum.sheetNames();
        let urlList = [];
        for (let name of sheets) {
            let url = DataEnum.getUrlByName(name);
            urlList.push({ url: url, type: Laya.Loader.JSON })
        }

        Laya.loader.load(urlList, Laya.Handler.create(this, () => {
            for (let name of sheets) {
                let url = DataEnum.getUrlByName(name);
                let data = Laya.loader.getRes(url);
                this.data[name] = JSON.parse(data);
                Laya.loader.clearRes(url);
            }

        }), progress)
    }

    static getDataList(name: DataEnum) {

    }
}
